import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class CSVExport
{
	public static void main(String[] args)
	{
		Product p1 = new Product("123","Bag","red","nike","L","Jamil");
		Product p2 = new Product("234","Ball","blue","rebok","S","Vineet");
		Product p3 = new Product("345","Box","green","vip","M","Jack");
		Product p4 = new Product("456","Belt","yellow","addidas","XL","Jim");
		Product p5 = new Product("567","Bat","Black","addidas","M","John");
		
		BigDecimal q1 = new BigDecimal(2);
		BigDecimal q2 = new BigDecimal(3);
		BigDecimal q3 = new BigDecimal(4);
		BigDecimal q4 = new BigDecimal(5);
		BigDecimal q5 = new BigDecimal(6);
		
		Map <String,BigDecimal> quantityMap = new HashMap <String, BigDecimal>();
		quantityMap.put("123", q1);
		quantityMap.put("234", q2);
		quantityMap.put("345", q3);
		quantityMap.put("456", q4);
		quantityMap.put("567", q5);
		
		List <Product> productList = new ArrayList <Product>();
		productList.add(p1);
		productList.add(p2);
		productList.add(p3);
		productList.add(p4);
		productList.add(p5);
		
		Iterator <Product> prodItr = productList.iterator();
		
		List <String> header = new ArrayList <String>();
		header.add("Name");
		header.add("Supplier");
		header.add("Quantity");
		
		Iterator <String> headerItr = header.iterator();
		
		File f = new File("E:/Export.csv");
		try 
		{
			FileWriter fw = new FileWriter(f);
			while(headerItr.hasNext())
			{
				String h = headerItr.next();
				fw.write(h);
				if(headerItr.hasNext())
				{
					fw.write(",");
				}
			}
			while(prodItr.hasNext())
			{
				Product prod = prodItr.next();
				String SKU = prod.getSKU();
				String name = prod.getName();
				String color = prod.getColor();
				String brand = prod.getBrand();
				String size = prod.getSize();
				String supplier = prod.getSupplier();
				int qty = (quantityMap.get(SKU)).intValue();
				fw.write("\n" + name +" ("+ color +" "+ brand +" "+ size +"),"+ supplier +","+ qty);
			}
			fw.flush();
			fw.close();	
		} 
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}

}
